<extend name="Public:base" />
<block name="header_js">

<script type="text/javascript">
$(function () {
	//缩略图上传
	var litpic_tip = $(".litpic_tip");
	var btn = $(".up-picture-btn span");
	$("#fileupload").wrap("<form id='myupload' action='{:U('Public/upload',array('img_flag' => 1))}' method='post' enctype='multipart/form-data'></form>");
    $("#fileupload").change(function(){
    	if($("#fileupload").val() == "") return;
		$("#myupload").ajaxSubmit({
			dataType:  'json',
			beforeSend: function() {
        		$('#litpic_show').empty();
				btn.html("上传中...");
    		},
			success: function(data) {
				if(data.state == 'SUCCESS'){
					var fileSize = parseFloat(data.info[0].size/1024).toFixed(2);
					litpic_tip.html(""+ data.info[0].name +" 上传成功("+ fileSize +"k)");
					var img = data.info[0].url;//原图
					//var timg = data.info[0].turl;//缩略图
					$('#litpic_show').html("<img src='"+img+"' width='120'>");
					$("#litpic").val(img);
				}else {
					litpic_tip.html(data.state);		
				}			
					btn.html("添加图片");

			},
			error:function(xhr){
				btn.html("上传失败");
				litpic_tip.html(xhr);
			}
		});
	});
	
});




$(function () {

	$('#BrowerPicture').click(function(){
		layer.open({
			type: 2,
			title: 'XYHCMS',
			shadeClose: true,
			shade: 0.5,
			area: ['670px', '350px'],
			content: "{:U('Public/browseFile', array('stype' => 'picture'))}"
		});
	});	

});


function selectPicture(sfile) {
	layer.msg('选择文件成功')
	$("#litpic").val(sfile);
	$('#litpic_show').html("<img src='"+sfile+"' width='120'>");
}



</script>
	
</block>

<block name="content">
	<div class="row">
		<div class="col-lg-12">
			<h3 class="page-header"><em class="glyphicon glyphicon-cloud-upload"></em> 
			添加友情链接  
		    </h3>
		</div>
		
	</div>


	<div class="row">
		<div class="col-lg-12">

				<form method='post' class="form-horizontal" id="form_do" name="form_do" action="{:U('add')}">											

					<div class="form-group">
						<label for="inputName" class="col-sm-2 control-label">网站名称</label>
						<div class="col-sm-9">
							<input type="text" name="name" id="inputName" class="form-control" placeholder="网站名称" required="required" />									
						</div>
					</div>
					<div class="form-group">
						<label for="inputUrl" class="col-sm-2 control-label">网站地址</label>
						<div class="col-sm-9">
							<input type="text" name="url" id="inputUrl" value="http://" class="form-control" placeholder="副标题" />									
						</div>
					</div>
					<div class="form-group">
						<label for="litpic" class="col-sm-2 control-label">网站Logo</label>
						<div class="col-sm-5">
							    <input type="text" class="form-control" name="logo" id="litpic"  value="" placeholder="网站Logo" />	
						</div>
						<div class="col-sm-5">
							<button class="btn btn-primary" type="button" id="BrowerPicture"><em class="glyphicon glyphicon-plus-sign"></em> 选择站内图片</button>
								<div class="btn btn-success up-picture-btn">
							        <span><em class="glyphicon glyphicon-plus-sign"></em>上传Logo</span>							        
							        <input id="fileupload" type="file" name="mypic">
							    </div>							
						</div>
					</div>


					<div class="form-group">
						<label for="" class="col-sm-2 control-label"></label>
						<div class="col-sm-9">
							<div class="litpic_tip"></div>
							<div id="litpic_show"> </div>							
						</div>
					</div>

					<div class="form-group">
						<label for="inputSort" class="col-sm-2 control-label">排列位置</label>
						<div class="col-sm-9">
							<input type="text" name="sort" id="inputSort" value="1" class="form-control" value="" placeholder="排列位置" />						
						</div>
					</div>

					<div class="form-group">
						<label for="inputDescription" class="col-sm-2 control-label">网站简况</label>
						<div class="col-sm-9">
							<textarea name="description" id="inputDescription" class="form-control"></textarea>								
						</div>
					</div>

					<div class="form-group">
						<label for="inputName" class="col-sm-2 control-label">链接位置</label>
						<div class="col-sm-9">
							<label class="radio-inline">
							 	<input type="radio" name="ischeck" value="0" checked="checked" />首页				
							 </label>
							<label class="radio-inline">
							 	<input type="radio" name="ischeck" value="1" />内页		
							 </label>	
						</div>
					</div>		
					
					<div class="row margin-botton-large">
						<div class="col-sm-offset-2 col-sm-9">
							<div class="btn-group">
								<button type="submit" class="btn btn-primary"> <i class="glyphicon glyphicon-saved"></i>
									保存
								</button>
								<button type="button" onclick="goUrl('{:U('index')}')" class="btn btn-default"> <i class="glyphicon glyphicon-chevron-left"></i>
									返回
								</button>
							</div>
						</div>
					</div>
				</form>
	
		</div>
	</div>

		


</block>